package com.tf_cut.admin.platform.controller;

import com.alibaba.fastjson.JSON;
import com.tf_cut.admin.backend.api.BackEndApi;
import com.tf_cut.admin.common.pojo.PageInfo;
import com.tf_cut.admin.common.pojo.Result;
import com.tf_cut.admin.platform.vo.AgentWithdrawVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


@RestController
@RequestMapping("/platform/agent/withdraw")
@Slf4j
public class AgentWithdrawController {

    @Autowired
    private BackEndApi platformAgentWithdrawApi;

    @GetMapping("list")
    public ModelAndView sellerList() {
        return new ModelAndView("platform/agent/withdraw/list", "platformAgentWithdraw", null);
    }

    @GetMapping(value = "list/page")
    public Result<PageInfo<AgentWithdrawVo>> queryAgentWithdrawList(AgentWithdrawVo agentWithdrawVo) {
        String reqJson = JSON.toJSONString(agentWithdrawVo);
        String json = platformAgentWithdrawApi.queryAgentWithdrawList(reqJson);
        return Result.of(JSON.parseObject(json, PageInfo.class));
    }

    @PostMapping("update")
    public String updateAgentWithdraw(AgentWithdrawVo agentWithdrawVo) {
        String rtnJson = "";
        if (null != agentWithdrawVo.getOrderType() && StringUtils.isNoneBlank(agentWithdrawVo.getOrderId())) {
            try {
                rtnJson = platformAgentWithdrawApi.updateAgentCash(JSON.toJSONString(agentWithdrawVo));
            } catch (Exception e) {
                log.error("updateAgentWithdraw reqParam={},error:{}",JSON.toJSONString(agentWithdrawVo),e.getMessage(), e);
            }
        }
        return rtnJson;
    }

}
